//
//  XMChatCell.m
//  XMJJ_zmy
//
//  Created by 丁浩 on 2025/7/4.
//

#import "XMChatCell.h"

@interface XMChatCell ()

@property (nonatomic, strong) UILabel *imgView;

@end

@implementation XMChatCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.backgroundColor = kColorHEX(0xF7F7F7);
    [self addSubview:self.avatarImg];    
}

- (void)setIsSelf:(BOOL)isSelf {
    _isSelf = isSelf;
    [self addSubview:self.avatarImg];
    if (isSelf) {
        self.avatarImg.x = kScreenWidth - KScaleWidth(10.0) - _avatarImg.width;
//        [_avatarImg sd_setImageWithURL:[NSURL URLWithString:senderAvatarImg] placeholderImage:ImageNamed(@"mine_avatar_icon")];
    }
    else {
        self.avatarImg.x = KScaleWidth(10.0);
    }
}

- (void)setContentWithMessage:(V2TIMMessage *)message
                 senderAvatar:(nonnull NSString *)senderAvatarImg
               receiverAvatar:(nonnull NSString *)receiverAvatarImg {
    if (message.isSelf) {
        self.avatarImg.x = kScreenWidth - KScaleWidth(10.0) - _avatarImg.width;
        [_avatarImg sd_setImageWithURL:[NSURL URLWithString:senderAvatarImg] placeholderImage:ImageNamed(@"mine_avatar_icon")];
//        [self setSenderMsgContentWithMessage:message];
    }
    else {
        self.avatarImg.x = KScaleWidth(10.0);
//        self.contentBgView.x = _avatarImg.maxX + KScaleWidth(10.0);
//        self.contentLabel.x = KScaleWidth(10.0);
//        [_avatarImg sd_setImageWithURL:[NSURL URLWithString:receiverAvatarImg] placeholderImage:ImageNamed(@"mine_avatar_icon")];
//        [self setReceiverMsgContentWithMessage:message];
    }
}

//- (void)setSenderMsgContentWithMessage:(V2TIMMessage *)message {
//    switch (message.elemType) {
//        case V2TIM_ELEM_TYPE_TEXT: {
//            CGFloat width = [message.textElem.text getWidthWithFont:KScaleWidth(14.0)] + KScaleWidth(18.0)*2;
//            if (width > MAXWIDTH) {
//                CGFloat height = [message.textElem.text getHeightWithFont:KScaleWidth(14.0) withWidth:MAXWIDTH - KScaleWidth(18.0)*2];
//                _contentBgView.x = _avatarImg.width + KScaleWidth(10.0)*2;
//                _contentBgView.width = MAXWIDTH;
//                _contentBgView.height = height + KScaleWidth(20.0);
////                [_contentLabel setCornerRadius:KScaleWidth(18.0)];
//                _contentLabel.height = height + KScaleWidth(20.0);
//                _contentLabel.width = MAXWIDTH - KScaleWidth(18.0)*2;
//                _contentLabel.x = _contentBgView.width - KScaleWidth(10.0) - _contentLabel.width;
////                _contentLabel.textAlignment = NSTextAlignmentCenter;
//                _contentLabel.text = message.textElem.text;
//            }
//            else {
//                _contentBgView.width = MAX(width, KScaleWidth(44.0));
//                _contentBgView.height = KScaleWidth(44.0);
//                _contentBgView.x = kScreenWidth - KScaleWidth(10.0)*2 - _avatarImg.width - _contentBgView.width;
//
//                _contentLabel.width = _contentBgView.width - KScaleWidth(18.0)*2 + KScaleWidth(5.0);
//                _contentLabel.text = message.textElem.text;
////                _contentLabel.textAlignment = NSTextAlignmentCenter;
//            }
//            [_contentBgView setCornerRadius:KScaleWidth(10.0)];
//        }
//            break;
//
//        default:
//            break;
//    }
//}
//
//- (void)setReceiverMsgContentWithMessage:(V2TIMMessage *)message {
//
//}

#pragma mark - Init
- (UIImageView *)avatarImg {
    if (!_avatarImg) {
        _avatarImg = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(10.0), KScaleWidth(8.0), KScaleWidth(44.0), KScaleWidth(44.0))];
        [_avatarImg setCornerRadius:KScaleWidth(10.0)];
    }
    return _avatarImg;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
